package com.github.beihaifeiwu.myspring.template.beetl;

import com.github.beihaifeiwu.myspring.core.MySpringConstants;
import com.github.beihaifeiwu.myspring.core.SpringContext;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.boot.autoconfigure.template.AbstractTemplateViewResolverProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.Resource;

/**
 * Created by liupin on 2017/5/9.
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ConfigurationProperties(prefix = MySpringConstants.BEETL_PROP_PREFIX)
public class BeetlProperties extends AbstractTemplateViewResolverProperties {

    public static final String DEFAULT_PREFIX = "";
    public static final String DEFAULT_SUFFIX = ".btl";

    private Resource config;
    private String root = "templates/";

    public BeetlProperties() {
        super(DEFAULT_PREFIX, DEFAULT_SUFFIX);
    }

    public Resource getConfig() {
        if (config == null) {
            config = SpringContext.getResource(MySpringConstants.DEFAULT_BEETL_CONFIG_SOURCE);
        }
        return config;
    }
}
